package com.gxc.blog.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.gxc.blogm.service.AlbumService;
import com.gxc.dbcore.util.PageInfo;
import com.gxc.dbcore.util.PageList;
import com.gxc.webcore.util.JsonUtil;
import com.gxc.webcore.util.RequestUtil;

public class AlbumController {

	AlbumService albumService;

	public AlbumService getAlbumService() {
		return albumService;
	}

	public void setAlbumService(AlbumService albumService) {
		this.albumService = albumService;
	}

	public ModelAndView list(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return new ModelAndView("blog/album/album_list.vm");
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public ModelAndView grid(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		PageInfo pageInfo = PageInfo.getFromRequest(request);
		Map params = RequestUtil.getInMap(request);
		PageList pageList = albumService.listPage(params, pageInfo);
		Map result = new HashMap();
		result.put("status", "success");
		result.put("data", pageList);
		String jsonResult = JsonUtil.object2json(result);
		response.getWriter().write(jsonResult);
		return null;
	}

}
